Skip to content

[WRONG BRANCH] fix(usage): bound incremental append reads - #278

Draft
luvs01 wants to merge 1 commit into
mainfrom
codex/fix-unbounded-incremental-log-read-issue
Draft

[WRONG BRANCH] fix(usage): bound incremental append reads#278
luvs01 wants to merge 1 commit into
mainfrom
codex/fix-unbounded-incremental-log-read-issue

Conversation

@luvs01

@luvs01 luvs01 commented Aug 14, 2026

Copy link
Copy Markdown
Owner

Motivation

  • The incremental retained-tail reader could read and parse every byte appended since the retained snapshot before applying maxReadBytes, violating the bounded-read contract and risking CPU/memory exhaustion on large append bursts.

Description

  • Add an early bound check in readUsageEntriesIncrementally (src/usage/log.ts) that abandons the incremental path and falls back to a bounded full-tail read when size - retained.coveredThroughBytes > maxReadBytes.
  • Add a regression test in tests/api-usage.test.ts that verifies a large append burst triggers a bounded full read rather than an unbounded incremental parse.
  • Preserve existing API semantics for callers: when the incremental path is refused, the reader performs the existing bounded full read to satisfy maxReadBytes.

Testing

  • bun run typecheck completed successfully.
  • bun run privacy:scan completed and passed.
  • bun test tests/api-usage.test.ts could not complete in this environment due to a runtime import error (zstdDecompressSync not found in node:zlib), so the new test was added but could not be exercised here; the failure appears environmental rather than related to the change.

Codex Task

Summary by CodeRabbit

  • Bug Fixes
    • Improved usage-log processing when large bursts of new data exceed the configured read limit.
    • Ensures the system performs a bounded full read and correctly accounts for available entries.

@github-actions

Copy link
Copy Markdown

Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Aug 14, 2026
@github-actions

github-actions Bot commented Aug 14, 2026

Copy link
Copy Markdown

⏳ DRAFT

  • wrong target branch (main); retarget to dev.

What to do

  • Retarget this PR to dev — all contributions go to dev.

Its title has been prefixed with [WRONG BRANCH].
This pull request was already a draft. Its draft status will be preserved after every issue above is resolved.

@github-actions github-actions Bot changed the title fix(usage): bound incremental append reads [WRONG BRANCH] fix(usage): bound incremental append reads Aug 14, 2026
@github-actions
github-actions Bot marked this pull request as draft August 14, 2026 03:49
@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 5c7a21ac-9726-4a43-823b-b01b471775c5

📥 Commits

Reviewing files that changed from the base of the PR and between 1a937d8 and 4af5cab.

📒 Files selected for processing (2)
  • src/usage/log.ts
  • tests/api-usage.test.ts

📝 Walkthrough

Walkthrough

Incremental usage-log reads now use a bounded full read when appended data exceeds maxReadBytes. A regression test verifies read counters, parsed-entry accounting, and bounded results.

Changes

Usage-log bounded fallback

Layer / File(s) Summary
Bounded incremental-read fallback
src/usage/log.ts, tests/api-usage.test.ts
At src/usage/log.ts:844-847, oversized appended data causes readUsageEntriesIncrementally to reject incremental extension. The test at tests/api-usage.test.ts:581-608 verifies a second full read, no tail read, parsed-entry accounting, and fewer than 100 returned entries.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 4af5c

This localized change bounds incremental reads while preserving the existing fallback behavior; no actionable merge-blocking risk remains at the current head after normal review.

Suggested reviewers: lidge-jun, harryzhou2000

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: bounding incremental append reads in usage logs.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-unbounded-incremental-log-read-issue

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aardvark bug Something isn't working codex

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant